/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************/
#include "websocketserver.h"
#include "echoserver.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QString>
#include <QDebug>
#include <QDateTime>
#include "powermanager.h"

//extern PowerManager* p_powerManger;

WebSocketServer::WebSocketServer(PowerManager *powerManageIn)
{
    powerManage=powerManageIn;
    objWebSocketServer = NULL;
    initial();
}




int WebSocketServer::initial()
{
    createWebSocketServer(8800);
//    setCallBackRecvText(WebSocketServer::funcCallBackRecvText);
//    setCallBackRecvBinary();

}
int WebSocketServer::closeClientSocket(QWebSocket *pClient)
{
    if(objWebSocketServer)
    {
        EchoServer* objEcho = (EchoServer*)objWebSocketServer;
        objEcho->CloseClientSocket(pClient);
        return 1;
    }
    return -1;

}

int WebSocketServer::createWebSocketServer(int localPort)
{

    if(!objWebSocketServer)
    {
        objWebSocketServer = (EchoServer*)(new EchoServer(localPort,this));
        return 1;
    }
    return -1;
}

int WebSocketServer::destroyWebSocketServer()
{
    if(objWebSocketServer)
    {
        EchoServer* objEchoServer = (EchoServer*)objWebSocketServer;
        delete objEchoServer;
        return 1;
    }
    return -1;
}

//void WebSocketServer::setCallBackRecvText(CallBackRecvText inCallBackRecvText)
//{
//    if(objWebSocketServer)
//    {
//        EchoServer* objEchoServer = (EchoServer*)objWebSocketServer;
//        objEchoServer->SetCallBackRecvText(inCallBackRecvText);
//    }
//}

//void WebSocketServer::setCallBackRecvBinary(CallBackRecvBinary inCallBackRecvText)
//{
//    if(objWebSocketServer)
//    {
//        EchoServer* objEchoServer = (EchoServer*)objWebSocketServer;
//        objEchoServer->SetCallBackRecvBinary(inCallBackRecvText);
//    }
//}

qint64 WebSocketServer::sendMsgText(QWebSocket *pClient,const QString& intSendData)
{
    qint64 errorCode = -1;
    if(objWebSocketServer)
    {
        EchoServer* objEchoServer = (EchoServer*)objWebSocketServer;
        errorCode = objEchoServer->SendMsgText(pClient,intSendData);
    }

    return errorCode;
}

qint64 WebSocketServer::sendMsgBinary(QWebSocket *pClient,const QByteArray& intSendData)
{
    qint64 errorCode = -1;
    if(objWebSocketServer)
    {
        EchoServer* objEchoServer = (EchoServer*)objWebSocketServer;
        errorCode = objEchoServer->SendMsgBinary(pClient,intSendData);
    }
    return errorCode;
}

void WebSocketServer::funcCallBackRecvBinary(QWebSocket *pClient, const QByteArray &outRecvData)
{

}

void WebSocketServer::funcCallBackRecvText(QWebSocket *pClient,const QString& outRecvData)
{
    QByteArray receiveByteArry = outRecvData.toLatin1();
//    qDebug() << "读出的数据如下：";
//    qDebug() << receiveByteArry;
    QJsonParseError jsonError;
    QJsonDocument receiveJsonDoc = QJsonDocument::fromJson(receiveByteArry, &jsonError);
    if(jsonError.error == QJsonParseError::NoError && !receiveJsonDoc.isNull())
    {
//      qDebug() << receiveJsonDoc;
    }
    QJsonObject redeiveJsonObj = receiveJsonDoc.object();

    //输出所有key，这一步是非必须的，放最后的话，你可能读不到任何key
    QStringList keys = redeiveJsonObj.keys();
    for(int i = 0; i < keys.size(); i++)
    {
//        qDebug() << "key" << i << " is:" << keys.at(i);
    }

    //因为是预先定义好的JSON数据格式，所以这里可以这样读取
    if(redeiveJsonObj.contains("manual_move"))
    {
       process_manual_move(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("manual_stop"))
    {
        process_manual_stop(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("get_battery_info"))
    {
        process_get_battery_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_login"))
    {
        process_login_in(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_servo"))
    {
        process_set_servo(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("set_clear_msg"))
    {
        process_set_clear_msg(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("set_mode"))
    {
        process_set_mode(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("set_manual_ratio"))
    {
        process_set_manual_ratio(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("set_auto_ratio"))
    {
        process_set_auto_ratio(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("set_run"))
    {
        process_set_run(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("set_cease"))
    {
        process_set_cease(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("set_stop"))
    {
        process_set_stop(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("set_clear_odomter"))
    {
        process_set_clear_odomter(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("set_create_map_start"))
    {
        process_set_create_map_start(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_save_map"))
    {
        process_set_save_map(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_load_map"))
    {
        process_set_load_map(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("get_basic_info"))
    {
        process_get_basic_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_msg_info"))
    {
        process_get_msg_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_map_list"))
    {
        process_get_map_list(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_vehicle_initial_position"))
    {
        process_set_vehicle_initial_position(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_vmark_type"))
    {
        process_set_vmark_type(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_di_name_info"))
    {
        process_get_di_name_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_dido_value_info"))
    {
        process_get_dido_value_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_do_name_info"))
    {
        process_get_do_name_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_do"))
    {
        process_set_do(redeiveJsonObj);
    }
    else if(redeiveJsonObj.contains("set_current_running_program_file"))
    {
        process_set_current_running_program_file(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_robot_program_file_list"))
    {
        process_get_robot_program_file_list(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_robot_program_files_strings"))
    {
        process_get_robot_program_files_strings(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_robot_running_program_files_info"))
    {
        process_get_robot_running_program_files_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_record_dpoint"))
    {
        process_set_record_dpoint(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_dpoint"))
    {
        process_get_dpoint(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_ultrasonic_sensor_check_info"))
    {
        //获取超声波检测数据
        process_get_ultrasonic_sensor_check_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_point_cloud_check_info"))
    {
        //获取点云检测数据
        process_get_point_cloud_check_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_ultrasonic_sensor_check_enable"))
    {
        //设置超声波检测数据
        process_set_ultrasonic_sensor_check_enable(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_point_cloud_check_enable"))
    {
        //设置点云检测数据
        process_set_point_cloud_check_enable(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_version_info"))
    {
        process_get_version_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_register_info"))
    {
        process_get_register_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_register"))
    {
        process_set_register(redeiveJsonObj,pClient);
    }
<<<<<<< HEAD
    else if(redeiveJsonObj.contains("move_to_navgation_point"))
    {
        process_move_to_navgation_point(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_vmark_laser_filter_type"))
    {
        process_set_vmark_laser_filter_type(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("get_vmark_debug_info"))
    {
        process_get_vmark_debug_info(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_run_line_number"))
    {
        process_set_program_line_number(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_default_file_name"))
    {
        process_set_default_program_name(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_default_map_name"))
    {
        process_set_default_map_name(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_shutdown"))
    {
        process_set_shutdown(redeiveJsonObj,pClient);
    }
    else if(redeiveJsonObj.contains("set_call_vehicle"))
    {
        process_set_call_vehicle(redeiveJsonObj,pClient);
    }
=======


>>>>>>> origin/master
}

int WebSocketServer::process_manual_move(QJsonObject &redeiveJsonObjIn)
{
   double move_x,move_y,move_rotate;
   QJsonObject subObj = redeiveJsonObjIn.value("manual_move").toObject();
   move_x=subObj["move_x"].toDouble();
   move_y =subObj["move_y"].toDouble();
   move_rotate=subObj["move_rotate"].toDouble();
   UserInfo tmpInfo;
   tmpInfo.account=subObj["user_type"].toInt();
   tmpInfo.password=subObj["user_password"].toString().toStdString();
   return powerManage->vehicleJog(tmpInfo,1,move_x,-move_y,move_rotate);//按钮需要更改Ｙ的正负号
}

int WebSocketServer::process_manual_stop(QJsonObject &redeiveJsonObjIn)
{
    qDebug()<<"WebSocketServer ,, jogStop";
    QJsonObject subObj = redeiveJsonObjIn.value("manual_stop").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    return powerManage->jogStop(tmpInfo);
}

int WebSocketServer::process_set_servo(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_servo").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int isOn=subObj["ison"].toInt();
    if(1==isOn)
    {
        return powerManage->servoOnAllRobot();
    }
    else
    {
        return powerManage->servoOffAllRobot();
    }
    return 1;

}

int WebSocketServer::process_set_clear_msg(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_clear_msg").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int tmpReturn ;
    return powerManage->setAllMsgClear(tmpInfo,tmpReturn);
}

int WebSocketServer::process_set_mode(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_mode").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int runModel=subObj["mode"].toInt();
    int tmpReturn ;
    return powerManage->setRunModel(tmpInfo,runModel,tmpReturn);
}

int WebSocketServer::process_set_manual_ratio(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_manual_ratio").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    double  ratio=subObj["ratio"].toDouble();
    int tmpReturn ;
    return powerManage->setManualSpeedPercent(tmpInfo,ratio,tmpReturn);
}

int WebSocketServer::process_set_auto_ratio(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_auto_ratio").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    double  ratio=subObj["ratio"].toDouble();
    int tmpReturn ;
    return powerManage->setAutoSpeedPercent(tmpInfo,ratio,tmpReturn);
}

int WebSocketServer::process_set_run(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_run").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int tmpReturn ;
    return powerManage->programRun(tmpInfo,tmpReturn);
}

int WebSocketServer::process_set_cease(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_cease").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int tmpReturn ;
    return powerManage->programCease(tmpInfo,tmpReturn);
}

int WebSocketServer::process_set_stop(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_stop").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int tmpReturn ;
    return powerManage->programReset(tmpInfo,tmpReturn);
}

int WebSocketServer::process_set_clear_odomter(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_clear_odomter").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int tmpReturn ;
    return powerManage->resetCustomOdometer_positionManage(tmpInfo,tmpReturn);
}

int WebSocketServer::process_set_create_map_start(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_create_map_start").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int tmpReturn ;
    powerManage->createMapStart(tmpInfo,tmpReturn);

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(tmpReturn));
    obj_root.insert("response_create_map_start", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
<<<<<<< HEAD
=======
    qDebug()<<tmpString;
>>>>>>> origin/master
    return 1;
}

int WebSocketServer::process_set_save_map(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_save_map").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    std::string mapName=subObj["map_name"].toString().toStdString();
    int tmpReturn ;
    int stateValue = powerManage->createMapEnd(tmpInfo,mapName,tmpReturn);


    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(tmpReturn));
    obj_root.insert("response_set_save_map", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
<<<<<<< HEAD
=======
    qDebug()<<tmpString;
>>>>>>> origin/master

     return stateValue;
}

int WebSocketServer::process_set_load_map(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_load_map").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    std::string mapName=subObj["map_name"].toString().toStdString();
    int tmpReturn ;
    return powerManage->loadMap(tmpInfo,mapName,tmpReturn);
}

int WebSocketServer::process_set_vehicle_initial_position(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_vehicle_initial_position").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int tmpReturn ;
    VehiclePosition positionIn;
    positionIn.x=subObj["position_x"].toDouble();
    positionIn.y=subObj["position_y"].toDouble();
    positionIn.rotate=subObj["position_r"].toDouble();
    powerManage->setVehiclePosition(tmpInfo,positionIn,tmpReturn);

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(tmpReturn));
    obj_root.insert("response_vehicle_initial_position", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
<<<<<<< HEAD
=======
    qDebug()<<tmpString;
>>>>>>> origin/master
    return 1;
}

int WebSocketServer::process_set_vmark_type(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_vmark_type").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int tmpReturn ;
    int type=subObj["vmark_type"].toDouble();

    powerManage->setCurrentVMarkType(tmpInfo,type,tmpReturn);

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(tmpReturn));
    obj_root.insert("response_vmark_type", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
<<<<<<< HEAD
=======
    qDebug()<<tmpString;
>>>>>>> origin/master
    return 1;
}

int WebSocketServer::process_get_battery_info(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_battery_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    BatteryInformation batteryInfoOut;
    powerManage->getBatteryInfo(batteryInfoOut);

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("lightmode", QString::number(batteryInfoOut.batteryLeftLightmodRatio));
    obj_root.insert("response_battery_info", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    return 1;
}

int WebSocketServer::process_login_in(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_login").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    int tmpReturn;
    powerManage->loginController_webhmi(tmpInfo,"",tmpReturn);

    QJsonObject obj_root;
    QJsonObject obj_info;
    obj_info.insert("result", tmpReturn);
    obj_root.insert("response_login", obj_info);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    return 1;
}

int WebSocketServer::process_get_basic_info(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_basic_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    //获取信息
    int tmpReturn;
    UpdateDataLv2 updateDataLv2;
    powerManage->updateControllerInfoLevel2(tmpInfo, updateDataLv2);
    double historyOdomOut, historyTimeOut,customOdomOut, customeTimeOut;
    powerManage->getOdometer_positionManage(tmpInfo,historyOdomOut, historyTimeOut,customOdomOut, customeTimeOut);
    //如果有数据为nan,则json会有问题。
    if(isnan(historyOdomOut))
    {
        historyOdomOut=-1;
    }
    if(isnan(customOdomOut))
    {
        customOdomOut=-1;
    }
    BatteryInformation batteryInfoOut;
    powerManage->getBatteryInfo(batteryInfoOut);
    std::string mapNameReturn;
    powerManage->getCurrentMapName(tmpInfo,mapNameReturn);
    VehicleVelocity velocityOut;
    powerManage->getVehicleSpeedFeedback(tmpInfo,velocityOut);
    PositionInfo_hmi position_amcl_Return;
    powerManage->getVehiclePosition_specified(tmpInfo,1,position_amcl_Return);
    PositionInfo_hmi position_vmark_Return;
<<<<<<< HEAD
    powerManage->getVehiclePosition_specified(tmpInfo,E_VEHICLE_POSITION_TYPE_VMARK,position_vmark_Return);
    PositionInfo_hmi position_qrcode_Return;
    powerManage->getVehiclePosition_specified(tmpInfo,E_VEHICLE_POSITION_TYPE_QRCODE,position_qrcode_Return);
=======
    powerManage->getVehiclePosition_specified(tmpInfo,6,position_vmark_Return);

>>>>>>> origin/master

    //发送信息
    QJsonObject obj_root;
    QJsonObject obj_basic_info;
    obj_basic_info.insert("mode", updateDataLv2.globalHandState);
    obj_basic_info.insert("manual_ratio", updateDataLv2.globalManSpeed);
    obj_basic_info.insert("auto_ratio", updateDataLv2.globalProSpeed);
    obj_basic_info.insert("vehicle_speed_line", velocityOut.x_move);
    obj_basic_info.insert("vehicle_speed_rotate", velocityOut.z_rotate);
    obj_basic_info.insert("battery_info", batteryInfoOut.batteryLeftLightmodRatio);
    obj_basic_info.insert("user_type", tmpInfo.account);
    obj_basic_info.insert("servo_status", updateDataLv2.globalServoState);
    obj_basic_info.insert("run_status", updateDataLv2.globalCurrentState);
    obj_basic_info.insert("odometer_history", historyOdomOut);
    obj_basic_info.insert("odometer_user", customOdomOut);
    obj_basic_info.insert("time_history", historyTimeOut);
    obj_basic_info.insert("time_user", customeTimeOut);
    obj_basic_info.insert("mainProgramFileVersion", updateDataLv2.mainProgramFileVersion);
    QString tmp_runningFile;
    int line=0;
    //hmi 运行程序一闪一闪可能时这个原因吗？
    if(updateDataLv2.currentRunFile.runingFileName.size()>0
            && updateDataLv2.currentRunFile.runningFileLine.size()>0)
    {
        tmp_runningFile=QString::fromStdString( updateDataLv2.currentRunFile.runingFileName[0]);
        line=updateDataLv2.currentRunFile.runningFileLine[0];
    }
    obj_basic_info.insert("current_file", tmp_runningFile);
    obj_basic_info.insert("current_file_running_line", line);

    obj_basic_info.insert("is_current_vehicle_position_map_sucess", position_amcl_Return.isUpdateSucess);
    obj_basic_info.insert("current_vehicle_position_map_match_score", position_amcl_Return.matchScore);
    obj_basic_info.insert("current_vehicle_position_map_x", position_amcl_Return.position.x);
    obj_basic_info.insert("current_vehicle_position_map_y", position_amcl_Return.position.y);
    obj_basic_info.insert("current_vehicle_position_map_r", position_amcl_Return.position.rotate);

    obj_basic_info.insert("is_current_vehicle_position_vmark_sucess", position_vmark_Return.isUpdateSucess);
    obj_basic_info.insert("current_vehicle_position_vmark_match_score", position_vmark_Return.matchScore);
    obj_basic_info.insert("current_vehicle_position_vmark_x", position_vmark_Return.position.x);
    obj_basic_info.insert("current_vehicle_position_vmark_y", position_vmark_Return.position.y);
    obj_basic_info.insert("current_vehicle_position_vmark_r", position_vmark_Return.position.rotate);

<<<<<<< HEAD
    obj_basic_info.insert("is_current_vehicle_position_qrcode_sucess", position_qrcode_Return.isUpdateSucess);
    obj_basic_info.insert("current_vehicle_position_qrcode_match_score", position_qrcode_Return.matchScore);
    obj_basic_info.insert("current_vehicle_position_qrcode_x", position_qrcode_Return.position.x);
    obj_basic_info.insert("current_vehicle_position_qrcode_y", position_qrcode_Return.position.y);
    obj_basic_info.insert("current_vehicle_position_qrcode_r", position_qrcode_Return.position.rotate);

=======
>>>>>>> origin/master
    obj_basic_info.insert("current_map", QString::fromStdString(mapNameReturn));
    obj_basic_info.insert("current_data", QString::fromStdString(updateDataLv2.currentTime));
    obj_basic_info.insert("currentRobotID", updateDataLv2.currentRobotID);

    obj_root.insert("response_basic_info", obj_basic_info);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    return 1;
}

int WebSocketServer::process_get_msg_info(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_msg_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    int tmpReturn;
    std::vector<struct Message> messageVector;
    powerManage->updateControllerMessage(tmpInfo,messageVector);
    QStringList tmpList;
    QString messageCode;
    QString timeStr;

    for(int i=0;i<messageVector.size();i++)
    {
        timeStr=longTimeToTimeString((messageVector[i].time));
        QString levelStr;
        switch(messageVector[i].MessageLevel)
        {
        case ENUM_MSG_REMIND:
        {
            levelStr="提示";
            break;
        }
        case ENUM_MSG_ERROR:
        {
            levelStr="错误";
            break;
        }
        case ENUM_MSG_WARNING:
        {
            levelStr="警告";
            break;
        }
        default:
        {
            levelStr="未知级别";
        }
        }
        timeStr=longTimeToTimeString((messageVector[i].time));
        messageCode=levelStr+":消息码";
        messageCode+=QString::number(messageVector[i].messageCode)+",";
        tmpList.append(timeStr+messageCode+QString::fromStdString(messageVector[i].MessageInformation));
    }

    QJsonObject obj_root;
    QJsonObject obj_info;
    QJsonArray arry_info;
    arry_info=arry_info.fromStringList(tmpList);
    obj_info.insert("msg_list", arry_info);

    obj_root.insert("response_msg_info", obj_info);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    return 1;
}

int WebSocketServer::process_get_map_list(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_map_list").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    int tmpReturn;
    std::vector<string> mapNameListOut;
    powerManage->getMapNameList(tmpInfo,mapNameListOut);
    QStringList tmpList;
    for(int i=0;i<mapNameListOut.size();i++)
    {
        tmpList.append(QString::fromStdString(mapNameListOut[i]));
    }

    QJsonObject obj_root;
    QJsonObject obj_info;
    QJsonArray arry_info;
    arry_info=arry_info.fromStringList(tmpList);
    obj_info.insert("map_list", arry_info);

    obj_root.insert("response_map_list", obj_info);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    return 1;
}

int WebSocketServer::process_get_di_name_info(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
//    qDebug()<<"WebSocketServer:: process_get_di_name_info";
    QJsonObject subObj = redeiveJsonObjIn.value("get_di_name_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    int tmpReturn;
    std::vector<string> mapNameListOut;
    tmpReturn = powerManage->get_di_names_info(tmpInfo,mapNameListOut);
    if(tmpReturn ==SOAP_OK)
    {
        QStringList tmpList;
        for(int i=0;i<mapNameListOut.size();i++)
        {
            tmpList.append(QString::fromStdString(mapNameListOut[i]));
        }

        QJsonObject obj_root;
        QJsonObject obj_info;
        QJsonArray arry_info;
        arry_info=arry_info.fromStringList(tmpList);
        obj_info.insert("name_info", arry_info);

        obj_root.insert("response_di_name_info", obj_info);

        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();
        sendMsgText(pClientIn,tmpString);
    //    qDebug()<<tmpString;
        return 1;
    }
<<<<<<< HEAD
=======

    QJsonObject obj_root;
    QJsonObject obj_info;
    QJsonArray arry_info;
    arry_info=arry_info.fromStringList(tmpList);
    obj_info.insert("name_info", arry_info);

    obj_root.insert("response_di_name_info", obj_info);

    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
//    qDebug()<<tmpString;
    return 1;
>>>>>>> origin/master
}


int WebSocketServer::process_get_do_name_info(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_do_name_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    int tmpReturn;
    std::vector<string> mapNameListOut;
    tmpReturn = powerManage->get_do_names_info(tmpInfo,mapNameListOut);
    if(tmpReturn == SOAP_OK)
    {
        QStringList tmpList;
        for(int i=0;i<mapNameListOut.size();i++)
        {
            tmpList.append(QString::fromStdString(mapNameListOut[i]));
        }

        QJsonObject obj_root;
        QJsonObject obj_info;
        QJsonArray arry_info;
        arry_info=arry_info.fromStringList(tmpList);
        obj_info.insert("name_info", arry_info);

        obj_root.insert("response_do_name_info", obj_info);
        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();
        sendMsgText(pClientIn,tmpString);
        return 1;
    }
<<<<<<< HEAD
=======

    QJsonObject obj_root;
    QJsonObject obj_info;
    QJsonArray arry_info;
    arry_info=arry_info.fromStringList(tmpList);
    obj_info.insert("name_info", arry_info);

    obj_root.insert("response_do_name_info", obj_info);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    return 1;
>>>>>>> origin/master
}

int WebSocketServer::process_get_dido_value_info(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_dido_value_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    int tmpReturn;

    UpdateDataLv3 updateDataLv3;
    powerManage->updateControllerInfoLevel3(tmpInfo, updateDataLv3);
    QStringList tmpDiList;
    for(int i=0;i<updateDataLv3.ioIn.size();i++)
    {
        tmpDiList.append(QString::number(updateDataLv3.ioIn[i]));
    }

    QStringList tmpDoList;
    for(int i=0;i<updateDataLv3.ioOut.size();i++)
    {
        tmpDoList.append(QString::number(updateDataLv3.ioOut[i]));
    }

    QJsonObject obj_root;
    QJsonObject obj_info;
    QJsonArray arry_info;
    arry_info=arry_info.fromStringList(tmpDiList);
    obj_info.insert("di_value_info", arry_info);
    arry_info=arry_info.fromStringList(tmpDoList);
    obj_info.insert("do_value_info", arry_info);

    obj_root.insert("response_dido_value_info", obj_info);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    return 1;
}

int WebSocketServer::process_set_do(QJsonObject &redeiveJsonObjIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_do").toObject();
    qDebug()<<"subObj"<<subObj;
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int tmpReturn ;

//    qDebug()<<"index="<<subObj["index"];
    int index=subObj["index"].toDouble();
//    int index=subObj["index"].toString().toInt();
//    bool value=subObj["value"].toBool();//double 字符转　ｂｏｏｌ全部为ｆａｌｓｅ
    bool value=subObj["value"].toInt();
//    qDebug()<<"value="<<subObj["value"];
//    qDebug()<<"WebSocketServer::process_set_do"<<index<<" "<<value;
    return powerManage->setDo(tmpInfo,index,value,tmpReturn);
}

int WebSocketServer::process_set_current_running_program_file(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_current_running_program_file").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
<<<<<<< HEAD

    int tmpReturn;
    string fileName=subObj["file_name"].toString().toStdString();
    powerManage->setProgramFileName(tmpInfo,fileName,tmpReturn);


    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(1));
    obj_root.insert("response_current_running_program_file", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);

=======

    int tmpReturn;
    string fileName=subObj["file_name"].toString().toStdString();
    powerManage->setProgramFileName(tmpInfo,fileName,tmpReturn);


    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(1));
    obj_root.insert("response_current_running_program_file", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);

>>>>>>> origin/master
    return 1;
}

int WebSocketServer::process_get_robot_program_file_list(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_robot_program_file_list").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    int tmpReturn;
    std::vector<string> mapNameListOut;
    powerManage->getRobotProgramFileList(tmpInfo,mapNameListOut);
    QStringList tmpList;
    for(int i=0;i<mapNameListOut.size();i++)
    {
        tmpList.append(QString::fromStdString(mapNameListOut[i]));
    }

    QJsonObject obj_root;
    QJsonObject obj_info;
    QJsonArray arry_info;
    arry_info=arry_info.fromStringList(tmpList);
    obj_info.insert("file_list", arry_info);

    obj_root.insert("response_robot_program_file_list", obj_info);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
<<<<<<< HEAD
    //qDebug()<<tmpString;
=======
//    qDebug()<<tmpString;
>>>>>>> origin/master
    return 1;
}

int WebSocketServer::process_get_robot_running_program_files_info(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_robot_running_program_files_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    std::vector<string> fileNames;
    std::vector<int> runningLines;
    powerManage->get_robot_running_program_files_info(tmpInfo,fileNames,runningLines);
<<<<<<< HEAD

    QJsonObject obj_root;
    QJsonObject obj_info;
    QJsonObject obj_run_info;
    QJsonArray arry_info;
    for(int i=0;i<fileNames.size();i++)
    {
        obj_run_info.insert("file_name", QString::fromStdString(fileNames[i]));
        obj_run_info.insert("file_current_line", runningLines[i]);
        arry_info.push_back(obj_run_info);
    }
    obj_info.insert("files_info", arry_info);

=======

    QJsonObject obj_root;
    QJsonObject obj_info;
    QJsonObject obj_run_info;
    QJsonArray arry_info;
    for(int i=0;i<fileNames.size();i++)
    {
        obj_run_info.insert("file_name", QString::fromStdString(fileNames[i]));
        obj_run_info.insert("file_current_line", runningLines[i]);
        arry_info.push_back(obj_run_info);
    }
    obj_info.insert("files_info", arry_info);

>>>>>>> origin/master
    obj_root.insert("response_robot_running_program_files_info", obj_info);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
//    qDebug()<<tmpString;
    return 1;
}

int WebSocketServer::process_get_robot_program_files_strings(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_robot_program_files_strings").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    std::vector<string> fileNames;
    std::vector<int> runningLines;
    QVector<QVector<QString> > programStrings;
<<<<<<< HEAD



    int languageType = tmpInfo.account=subObj["language_type"].toInt();

    if(languageType == ENUM_LAN_CHINESE)
    {
        //中文
    }
    else
    {
        //其他值认为是英文
        languageType = ENUM_LAN_ENGLISH;
    }

    powerManage->get_robot_program_files_strings(tmpInfo,languageType,fileNames,runningLines,programStrings);

    QJsonObject obj_root;
    QJsonObject obj_info;
    QJsonObject obj_run_info;
    QJsonArray arry_info;
    QJsonArray arry_lines_info;
    for(int i=0;i<fileNames.size();i++)
    {
        obj_run_info.insert("file_name", QString::fromStdString(fileNames[i]));
        obj_run_info.insert("file_current_line", runningLines[i]);
        QStringList tmpList;
        if(i<programStrings.size())
        {
            for(int j=0;j<programStrings[i].size();j++)
            {
                tmpList.append(programStrings[i][j]);
            }
            arry_lines_info=arry_lines_info.fromStringList(tmpList);
            obj_run_info.insert("file_lines", arry_lines_info);
            arry_info.push_back(obj_run_info);
        }
    }

    obj_info.insert("language_type", QString::number(languageType));
    obj_info.insert("files_info", arry_info);

=======
    powerManage->get_robot_program_files_strings(tmpInfo,fileNames,runningLines,programStrings);

    QJsonObject obj_root;
    QJsonObject obj_info;
    QJsonObject obj_run_info;
    QJsonArray arry_info;
    QJsonArray arry_lines_info;
    for(int i=0;i<fileNames.size();i++)
    {
        obj_run_info.insert("file_name", QString::fromStdString(fileNames[i]));
        obj_run_info.insert("file_current_line", runningLines[i]);
        QStringList tmpList;
        for(int j=0;j<programStrings[i].size();j++)
        {
            tmpList.append(programStrings[i][j]);
        }
        arry_lines_info=arry_lines_info.fromStringList(tmpList);
        obj_run_info.insert("file_lines", arry_lines_info);
        arry_info.push_back(obj_run_info);
    }

    obj_info.insert("files_info", arry_info);

>>>>>>> origin/master
    obj_root.insert("response_robot_program_files_strings", obj_info);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
<<<<<<< HEAD
    //qDebug()<<tmpString;
=======
//    qDebug()<<tmpString;
>>>>>>> origin/master
    return 1;
}

int WebSocketServer::process_set_record_dpoint(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_record_dpoint").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
<<<<<<< HEAD

    DPoint pointOut;
    string fileName=subObj["program_file_name"].toString().toStdString();
    pointOut.mapName=subObj["map_name"].toString().toStdString();
    pointOut.dpIndex=subObj["dpoint_index"].toString().toInt();
    pointOut.posX=subObj["dpoint_x"].toDouble();
    pointOut.posY=subObj["dpoint_y"].toDouble();
    pointOut.posR=subObj["dpoint_r"].toDouble();
    //需要改进
    pointOut.pointType=(MOVE_FREE_POINT_TYPE)(subObj["dp_type"].toInt()+1);//改成枚举了。

=======

    DPoint pointOut;
    string fileName=subObj["program_file_name"].toString().toStdString();
    pointOut.mapName=subObj["map_name"].toString().toStdString();
    pointOut.dpIndex=subObj["dpoint_index"].toString().toInt();
    pointOut.posX=subObj["dpoint_x"].toDouble();
    pointOut.posY=subObj["dpoint_y"].toDouble();
    pointOut.posR=subObj["dpoint_r"].toDouble();


>>>>>>> origin/master
    powerManage->recordDpoint(tmpInfo,fileName,pointOut);

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(1));
    obj_root.insert("response_record_dpoint", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
<<<<<<< HEAD
    //qDebug()<<tmpString;
=======
    qDebug()<<tmpString;
>>>>>>> origin/master
    return 1;
}

int WebSocketServer::process_get_dpoint(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_dpoint").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    string fileName=subObj["file_name"].toString().toStdString();
    int pointIndex=subObj["point_index"].toString().toInt();

    DPoint pointOut;
    powerManage->getDpoint(tmpInfo,fileName,pointIndex,pointOut);
<<<<<<< HEAD

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("program_file_name", QString::fromStdString(fileName));
    obj_batteryInfo.insert("map_name", QString::fromStdString(pointOut.mapName));
    obj_batteryInfo.insert("dpoint_index", QString::number(pointOut.dpIndex));
    obj_batteryInfo.insert("dpoint_x", QString::number(pointOut.posX));
    obj_batteryInfo.insert("dpoint_y", QString::number(pointOut.posY));
    obj_batteryInfo.insert("dpoint_r", QString::number(pointOut.posR));
    obj_batteryInfo.insert("dp_type", QString::number(pointOut.pointType-1));//需要改进，枚举类型修改

    obj_root.insert("response_dpoint", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    //qDebug()<<tmpString;
    return 1;
}


//超声波检测获取
int WebSocketServer::process_get_ultrasonic_sensor_check_info(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_ultrasonic_sensor_check_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    std::vector<double> safeStatus;
    bool isCheckEnable = false;

    if(powerManage->getUltrasonicSensorSafeStatus(safeStatus,isCheckEnable) == 1)
    {
        //获取成功
        QJsonObject obj_root;
        QJsonObject obj_data_info;
        QJsonArray arry_data_info;

        //QStringList tmpList;
        for(int i=0;i<safeStatus.size();i++)
        {
            //tmpList.append(safeStatus[i]);
            arry_data_info.push_back(safeStatus[i]);
        }

       // arry_data_info=arry_data_info.fromStringList(tmpList);

        if(isCheckEnable)
        {
            obj_data_info.insert("check_enable", 1);
        }
        else
        {
            obj_data_info.insert("check_enable", 0);
        }


        obj_data_info.insert("info_list", arry_data_info);

        obj_root.insert("response_ultrasonic_sensor_check_info", obj_data_info);
        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();
        sendMsgText(pClientIn,tmpString);
    }
    return 1;
}
int WebSocketServer::process_get_point_cloud_check_info(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_point_cloud_check_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    std::vector<std::string > sensorName;
    std::vector<double> sensorSafeRatio;
    bool isCheckEnable = false;

    if(powerManage->getPointCloudSafeStatus(sensorName,sensorSafeRatio,isCheckEnable) == 1)
    {
        //获取成功
        QJsonObject obj_root;
        QJsonObject obj_data_info;
        QJsonArray arry_data_info;
        //QStringList tmpList;
        for(int i=0;i<sensorName.size();i++)
        {
            QJsonObject obj_data_info_item;
            obj_data_info_item.insert("data_name",sensorName[i].data());
            obj_data_info_item.insert("data_value",sensorSafeRatio[i]);
            arry_data_info.push_back(obj_data_info_item);
        }
        if(isCheckEnable)
        {
            obj_data_info.insert("check_enable", 1);
        }
        else
        {
            obj_data_info.insert("check_enable", 0);
        }

        obj_data_info.insert("info_list", arry_data_info);

        obj_root.insert("response_point_cloud_check_info", obj_data_info);
        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();
        sendMsgText(pClientIn,tmpString);

    }
    else
    {
        return -1;
    }
    return 1;
}
int WebSocketServer::process_set_ultrasonic_sensor_check_enable(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_ultrasonic_sensor_check_enable").toObject();
    UserInfo tmpInfo;
    int check_enable = 0;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    check_enable = subObj["check_enable"].toInt();

    bool isCheckEnable = false;
    if(check_enable == 1)
    {
        isCheckEnable = true;
    }

    int resultCode = 0;
    if(powerManage->setUltrasonicSensorCheckEnable(isCheckEnable) == 1)
    {
        resultCode = 1;
    }
    else
    {
        return -1;
    }

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(resultCode));
    obj_root.insert("response_ultrasonic_sensor_check_type", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    qDebug()<<tmpString;

    return 1;
}

int WebSocketServer::process_set_point_cloud_check_enable(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_point_cloud_check_enable").toObject();
    UserInfo tmpInfo;
    int check_enable = 0;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();


    check_enable = subObj["check_enable"].toInt();

    bool isCheckEnable = false;

    if(check_enable == 1)
    {
        isCheckEnable = true;
    }

    int resultCode = 0;
    if(powerManage->setPointCloudCheckEnable(isCheckEnable) == 1)
    {
        resultCode = 1;
    }
    else
    {
        return -1;
    }

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(resultCode));
    obj_root.insert("response_point_cloud_check_type", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    qDebug()<<tmpString;
    return 1;
}


int WebSocketServer::process_get_version_info(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_version_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();


    UpdateDataLv1 updateDataLv1;
    if(powerManage->getUpdateControllerInfoLevel1(tmpInfo,updateDataLv1) == 1)
    {
        //获取成功
        QJsonObject obj_root;
        QJsonObject obj_data_info;
        QJsonArray arry_data_info;
        //QStringList tmpList;


        QJsonObject obj_data_info_item;

        obj_data_info_item.insert("mode_name","mainProgram");
        obj_data_info_item.insert("mode_version",updateDataLv1.mainProgramVersion.data());
        obj_data_info_item.insert("release_time","*");
        arry_data_info.push_back(obj_data_info_item);

        for(int i=0;i<updateDataLv1.componentVersionList.size();i++)
        {
            obj_data_info_item.empty();
            obj_data_info_item.insert("mode_name",updateDataLv1.componentVersionList.at(i).componentName.data());
            obj_data_info_item.insert("mode_version",updateDataLv1.componentVersionList.at(i).componentVersion.data());
            obj_data_info_item.insert("release_time",updateDataLv1.componentVersionList.at(i).publishDate.data());
            arry_data_info.push_back(obj_data_info_item);
        }
        obj_data_info.insert("controller_version", arry_data_info);
        obj_root.insert("response_version_info", obj_data_info);
        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();
        qDebug()<<tmpString;
        sendMsgText(pClientIn,tmpString);
    }
    else
    {
        return -1;
    }
    return 1;
}
int WebSocketServer::process_get_register_info(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_register_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    UpdateDataLv1 updateDataLv1;

    if(powerManage->getUpdateControllerInfoLevel1(tmpInfo,updateDataLv1) == 1)
    {
        //获取成功
        QJsonObject obj_root;
        QJsonObject obj_data_info;
        QString currentTime;

        currentTime = QDateTime::currentDateTime().toString("yyyyMMdd");

        obj_data_info.insert("register_status", updateDataLv1.globalRegStatus);
        obj_data_info.insert("register_number", updateDataLv1.serialNumber.data());
        obj_data_info.insert("lock_time", updateDataLv1.globalLockMachTime.data());
        obj_data_info.insert("current_time", currentTime);
        obj_data_info.insert("license_number", updateDataLv1.registerNumber.data());

        obj_root.insert("response_register_info", obj_data_info);
        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();
        qDebug()<<tmpString;

        sendMsgText(pClientIn,tmpString);

    }
    else
    {
        return -1;
    }
    return 1;
}

int WebSocketServer::process_set_register(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_register").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    string licenseNumber = "";
    licenseNumber=subObj["license_number"].toString().toStdString();
    ReturnRegisterStatus returnStatus;
    int resultCode = 0; //注册结果默认为失败
    if(powerManage->setRegisterNumber(tmpInfo,licenseNumber,returnStatus) == 0)
    {
        //注册结果为成功
        resultCode = 1;
    }

    QJsonObject obj_root;
    QJsonObject obj_setRegisterInfo;
    if(resultCode == 1)
    {
        obj_setRegisterInfo.insert("register_status", returnStatus.returnStatus);
        obj_setRegisterInfo.insert("lock_time", returnStatus.returnLockTime.data());
        obj_setRegisterInfo.insert("license_number", returnStatus.returnRegisterNumber.data());
    }

    obj_setRegisterInfo.insert("result", QString::number(resultCode));

    obj_root.insert("response_register", obj_setRegisterInfo);

    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    //qDebug()<<tmpString;
    return 1;
}
int WebSocketServer::process_move_to_navgation_point(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("move_to_navgation_point").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    MovingToNavagationParameter parameterIn;
    parameterIn.x = subObj["dpoint_x"].toDouble();
    parameterIn.y = subObj["dpoint_y"].toDouble();
    parameterIn.rotate = subObj["dpoint_r"].toDouble();
    parameterIn.speedRatio = subObj["speed_ratio"].toInt();
    if( subObj["positive_direction"].toInt() == 1 )
    {
        parameterIn.isPositiveDirection = true;
    }
    else
    {
        parameterIn.isPositiveDirection = false;
    }

    parameterIn.isPositiveDirection = subObj["positive_direction"].toInt();
//    parameterIn.pointType = subObj["dp_type"].toInt();
//    parameterIn.qrcodeTypeNum = subObj["qrcode_type_num"].toInt();
    parameterIn.vmarkTypeNum = subObj["vmark_type_num"].toInt();
    parameterIn.laserTypeNum = subObj["laser_type_num"].toInt();
    if( subObj["detect_barrier"].toInt() == 1 )//webHmi提取不对，需要改进。
    {
        parameterIn.isDetectBarrier = 1;
    }
    else
    {
        parameterIn.isDetectBarrier = 0;
    }
    parameterIn.isDetectBarrier = 1;//webHmi提取不对，需要改进。
    parameterIn.barrierRunMode=0;
    parameterIn.moveFreeMode=E_MOVE_FREE_IMU;
    if(0==parameterIn.vmarkTypeNum)
    {
        parameterIn.pointSensorType=EM_MOVE_FREE_DP;
    }
    else
    {
        parameterIn.pointSensorType=EM_MOVE_FREE_VMARK;
    }
    parameterIn.CNT_Value=0;
    parameterIn.moveFreeMoveTrajectoryType=E_MOVE_FREE_MOVE_TRAJECTORY_LINE;
    parameterIn.allowAccuracy=0.25;
    parameterIn.pathControlStrategy=E_PATH_CONTROL_STRATEGY_DIFFERENTIAL;


    int returnFlag = 0;

    powerManage->moveToNavgationPoint(tmpInfo,parameterIn,returnFlag);

    QJsonObject obj_root;
    QJsonObject obj_result;
    if(returnFlag == 1)
    {
       obj_result.insert("result", QString::number(1));
    }
    else
    {
       obj_result.insert("result", QString::number(0));
    }
    obj_root.insert("response_move_to_navgation_point", obj_result);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    qDebug()<<tmpString;
    return 1;
}

int WebSocketServer::process_set_vmark_laser_filter_type(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    //
    QJsonObject subObj = redeiveJsonObjIn.value("set_vmark_laser_filter_type").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    int laser_number = subObj["laser_filter_type"].toInt();
    int tmpReturn;
    powerManage->setLaserIntensityFilterByType_visionMatch(tmpInfo,laser_number,tmpReturn);

    QJsonObject obj_root;
    QJsonObject obj_result;

    obj_result.insert("result", QString::number(1));
    obj_root.insert("response_set_vmark_laser_filter_type", obj_result);

    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);


}
int WebSocketServer::process_get_vmark_debug_info(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_vmark_debug_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();


    VisionMatchDebugInfo infoOut;

    powerManage->getMatchDebugInfo_vmark(tmpInfo,infoOut);

    //获取成功
    QJsonObject obj_root;
    QJsonObject obj_data_info;
    QJsonArray arry_data_info;
    //QStringList tmpList;


    QJsonObject obj_data_info_item;

    obj_data_info_item.insert("item_name","isMatchSucess");
    obj_data_info_item.insert("item_value",QString::number(infoOut.isMatchSucess));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","angleOfLinesOut(degree)");
    obj_data_info_item.insert("item_value",QString::number(infoOut.angleOfLinesOut*180.0/M_PI,'f',3));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","struct_Line1Count");
    obj_data_info_item.insert("item_value",QString::number(infoOut.struct_Line1Count));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","currentVmarkType");
    obj_data_info_item.insert("item_value",QString::number(infoOut.currentVmarkType));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","laserFilterType");
    obj_data_info_item.insert("item_value",QString::number(infoOut.currentLaserFilterType));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","minConsumed(us)");
    obj_data_info_item.insert("item_value",QString::number(infoOut.minConsumed,'f',3));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","maxConsumed");
    obj_data_info_item.insert("item_value",QString::number(infoOut.maxConsumed,'f',3));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","currentConsumed");
    obj_data_info_item.insert("item_value",QString::number(infoOut.currentConsumed,'f',3));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","struct_Line1Corelation");
    obj_data_info_item.insert("item_value",QString::number(infoOut.struct_Line1Corelation,'f',3));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","struct_Line2Corelation");
    obj_data_info_item.insert("item_value",QString::number(infoOut.struct_Line2Corelation,'f',3));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","detectFailedType");
    obj_data_info_item.insert("item_value",QString::number(infoOut.detectFailedType));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","detectedLineCount");
    obj_data_info_item.insert("item_value",QString::number(infoOut.detectedLineCount));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","detectedVmarkCount");
    obj_data_info_item.insert("item_value",QString::number(infoOut.detectedVmarkCount));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","detectedVmarkResultCount");
    obj_data_info_item.insert("item_value",QString::number(infoOut.detectedVmarkResultCount));
    arry_data_info.push_back(obj_data_info_item);

    obj_data_info_item.insert("item_name","distanceOfLinesOut");
    obj_data_info_item.insert("item_value",QString::number(infoOut.distanceOfLinesOut));
    arry_data_info.push_back(obj_data_info_item);


    obj_data_info.insert("debug_info", arry_data_info);
    obj_root.insert("response_vmark_debug_info", obj_data_info);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);

    return 1;



}
int WebSocketServer::process_set_program_line_number(QJsonObject &redeiveJsonObjIn, QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_run_line_number").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int line_number = subObj["line_number"].toInt();
    int returnFlag = 0;
    powerManage->setProgramRunLine(tmpInfo,line_number,returnFlag);

    QJsonObject obj_root;
    QJsonObject obj_result;
    if(returnFlag == 0)
    {
        //设置成功
        obj_result.insert("result", QString::number(1));
    }
    else
    {
        //失败没有权限
        obj_result.insert("result", QString::number(0));
    }
    obj_root.insert("response_set_run_line_number", obj_result);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    return 1;
}
int WebSocketServer::process_set_default_program_name(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{

    QJsonObject subObj = redeiveJsonObjIn.value("set_default_file_name").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    QString defaultFileName = subObj["default_file_name"].toString();

    int returnFlag = 0;
    powerManage->setDefaultProgramFile(tmpInfo,defaultFileName.toStdString(),returnFlag);

    QJsonObject obj_root;
    QJsonObject obj_result;

    obj_result.insert("result", QString::number(returnFlag));

    obj_root.insert("response_set_default_file_name", obj_result);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);


    return 1;
}
int WebSocketServer::process_set_default_map_name(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{

    QJsonObject subObj = redeiveJsonObjIn.value("set_default_map_name").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    QString defaultMapName = subObj["map_name"].toString();

    int returnFlag = 0;
    QJsonObject obj_root;
    QJsonObject obj_result;

    if(defaultMapName.size()>0)
    {
        powerManage->setDefaultMapName(tmpInfo,defaultMapName.toStdString(),returnFlag);

        if(returnFlag == 1)
        {
            obj_result.insert("result", QString::number(1));
        }
        else
        {
            obj_result.insert("result", QString::number(0));
        }

    }
    else
    {
        obj_result.insert("result", QString::number(0));
    }


    obj_root.insert("response_set_default_map_name", obj_result);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);


=======

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("program_file_name", QString::fromStdString(fileName));
    obj_batteryInfo.insert("map_name", QString::fromStdString(pointOut.mapName));
    obj_batteryInfo.insert("dpoint_index", QString::number(pointOut.dpIndex));
    obj_batteryInfo.insert("dpoint_x", QString::number(pointOut.posX));
    obj_batteryInfo.insert("dpoint_y", QString::number(pointOut.posY));
    obj_batteryInfo.insert("dpoint_r", QString::number(pointOut.posR));
    obj_root.insert("response_dpoint", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    qDebug()<<tmpString;
    return 1;
}


//超声波检测获取
int WebSocketServer::process_get_ultrasonic_sensor_check_info(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_ultrasonic_sensor_check_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    std::vector<double> safeStatus;
    bool isCheckEnable = false;

    if(powerManage->getUltrasonicSensorSafeStatus(safeStatus,isCheckEnable) == 1)
    {
        //获取成功
        QJsonObject obj_root;
        QJsonObject obj_data_info;
        QJsonArray arry_data_info;

        //QStringList tmpList;
        for(int i=0;i<safeStatus.size();i++)
        {
            //tmpList.append(safeStatus[i]);
            arry_data_info.push_back(safeStatus[i]);
        }

       // arry_data_info=arry_data_info.fromStringList(tmpList);

        if(isCheckEnable)
        {
            obj_data_info.insert("check_enable", 1);
        }
        else
        {
            obj_data_info.insert("check_enable", 0);
        }


        obj_data_info.insert("info_list", arry_data_info);

        obj_root.insert("response_ultrasonic_sensor_check_info", obj_data_info);
        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();
        sendMsgText(pClientIn,tmpString);

    }


    return 1;
}
int WebSocketServer::process_get_point_cloud_check_info(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_point_cloud_check_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    std::vector<std::string > sensorName;
    std::vector<double> sensorSafeRatio;
    bool isCheckEnable = false;

    if(powerManage->getPointCloudSafeStatus(sensorName,sensorSafeRatio,isCheckEnable) == 1)
    {
        //获取成功
        QJsonObject obj_root;
        QJsonObject obj_data_info;
        QJsonArray arry_data_info;
        //QStringList tmpList;
        for(int i=0;i<sensorName.size();i++)
        {
            QJsonObject obj_data_info_item;
            obj_data_info_item.insert("data_name",sensorName[i].data());
            obj_data_info_item.insert("data_value",sensorSafeRatio[i]);
            arry_data_info.push_back(obj_data_info_item);
        }
        if(isCheckEnable)
        {
            obj_data_info.insert("check_enable", 1);
        }
        else
        {
            obj_data_info.insert("check_enable", 0);
        }


        obj_data_info.insert("info_list", arry_data_info);

        obj_root.insert("response_point_cloud_check_info", obj_data_info);
        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();
        sendMsgText(pClientIn,tmpString);

    }
    else
    {
        return -1;
    }
    return 1;
}
int WebSocketServer::process_set_ultrasonic_sensor_check_enable(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_ultrasonic_sensor_check_enable").toObject();
    UserInfo tmpInfo;
    int check_enable = 0;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    check_enable = subObj["check_enable"].toInt();

    bool isCheckEnable = false;
    if(check_enable == 1)
    {
        isCheckEnable = true;
    }

    int resultCode = 0;
    if(powerManage->setUltrasonicSensorCheckEnable(isCheckEnable) == 1)
    {
        resultCode = 1;
    }
    else
    {
        return -1;
    }

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(resultCode));
    obj_root.insert("response_ultrasonic_sensor_check_type", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    qDebug()<<tmpString;

    return 1;
}

int WebSocketServer::process_set_point_cloud_check_enable(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_point_cloud_check_enable").toObject();
    UserInfo tmpInfo;
    int check_enable = 0;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();


    check_enable = subObj["check_enable"].toInt();

    bool isCheckEnable = false;

    if(check_enable == 1)
    {
        isCheckEnable = true;
    }

    int resultCode = 0;
    if(powerManage->setPointCloudCheckEnable(isCheckEnable) == 1)
    {
        resultCode = 1;
    }
    else
    {
        return -1;
    }

    QJsonObject obj_root;
    QJsonObject obj_batteryInfo;
    obj_batteryInfo.insert("result", QString::number(resultCode));
    obj_root.insert("response_point_cloud_check_type", obj_batteryInfo);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    qDebug()<<tmpString;
    return 1;
}


int WebSocketServer::process_get_version_info(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_version_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();


    UpdateDataLv1 updateDataLv1;
    if(powerManage->getUpdateControllerInfoLevel1(tmpInfo,updateDataLv1) == 1)
    {
        //获取成功
        QJsonObject obj_root;
        QJsonObject obj_data_info;
        QJsonArray arry_data_info;
        //QStringList tmpList;


        QJsonObject obj_data_info_item;

        obj_data_info_item.insert("mode_name","mainProgram");
        obj_data_info_item.insert("mode_version",updateDataLv1.mainProgramVersion.data());
        obj_data_info_item.insert("release_time","*");
        arry_data_info.push_back(obj_data_info_item);

        for(int i=0;i<updateDataLv1.componentVersionList.size();i++)
        {
            obj_data_info_item.empty();
            obj_data_info_item.insert("mode_name",updateDataLv1.componentVersionList.at(i).componentName.data());
            obj_data_info_item.insert("mode_version",updateDataLv1.componentVersionList.at(i).componentVersion.data());
            obj_data_info_item.insert("release_time",updateDataLv1.componentVersionList.at(i).componentVersion.data());
            arry_data_info.push_back(obj_data_info_item);
        }
        obj_data_info.insert("controller_version", arry_data_info);
        obj_root.insert("response_version_info", obj_data_info);
        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();
        qDebug()<<tmpString;
        sendMsgText(pClientIn,tmpString);
    }
    else
    {
        return -1;
    }
    return 1;
}
int WebSocketServer::process_get_register_info(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("get_register_info").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    UpdateDataLv1 updateDataLv1;

    if(powerManage->getUpdateControllerInfoLevel1(tmpInfo,updateDataLv1) == 1)
    {
        //获取成功
        QJsonObject obj_root;
        QJsonObject obj_data_info;
        QString currentTime;

        currentTime = QDateTime::currentDateTime().toString("yyyyMMdd");

        obj_data_info.insert("register_status", updateDataLv1.globalRegStatus);
        obj_data_info.insert("register_number", updateDataLv1.serialNumber.data());
        obj_data_info.insert("lock_time", updateDataLv1.globalLockMachTime.data());
        obj_data_info.insert("current_time", currentTime);
        obj_data_info.insert("license_number", updateDataLv1.registerNumber.data());

        obj_root.insert("response_register_info", obj_data_info);
        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();
        qDebug()<<tmpString;

        sendMsgText(pClientIn,tmpString);

    }
    else
    {
        return -1;
    }
    return 1;
}

int WebSocketServer::process_set_register(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_register").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    string licenseNumber = "";
    licenseNumber=subObj["license_number"].toString().toStdString();
    ReturnRegisterStatus returnStatus;
    int resultCode = 0; //注册结果默认为失败
    if(powerManage->setRegisterNumber(tmpInfo,licenseNumber,returnStatus) == 0)
    {
        //注册结果为成功
        resultCode = 1;
    }

    QJsonObject obj_root;
    QJsonObject obj_setRegisterInfo;
    if(resultCode == 1)
    {
        obj_setRegisterInfo.insert("register_status", returnStatus.returnStatus);
        obj_setRegisterInfo.insert("lock_time", returnStatus.returnLockTime.data());
        obj_setRegisterInfo.insert("license_number", returnStatus.returnRegisterNumber.data());
    }

    obj_setRegisterInfo.insert("result", QString::number(resultCode));

    obj_root.insert("response_register", obj_setRegisterInfo);

    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);
    qDebug()<<tmpString;
>>>>>>> origin/master
    return 1;
}
int WebSocketServer::process_set_shutdown(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{
    QJsonObject subObj = redeiveJsonObjIn.value("set_shutdown").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();
    int shutdownType = subObj["shutdown_type"].toInt(); //1重启　0关机

    int returnFlag = 0;
    QJsonObject obj_root;
    QJsonObject obj_result;

    if(shutdownType == 1)
    {
        //
        powerManage->controllerShutDownAndReboot(tmpInfo,returnFlag);

        if(returnFlag == 0)
        {
            obj_result.insert("result", QString::number(1));
        }
        else
        {
            obj_result.insert("result", QString::number(0));
        }

    }
    else
    {
        powerManage->controllerShutDown(tmpInfo,returnFlag);

        if(returnFlag == 1)
        {
            obj_result.insert("result", QString::number(1));
        }
        else
        {
            obj_result.insert("result", QString::number(0));
        }
    }
    obj_result.insert("shutdown_type", QString::number(shutdownType));

    obj_root.insert("response_set_default_map_name", obj_result);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);

    return 1;
}

//单台车辆呼叫命令
int WebSocketServer::process_set_call_vehicle(QJsonObject &redeiveJsonObjIn,QWebSocket *pClientIn)
{

    QJsonObject subObj = redeiveJsonObjIn.value("set_call_vehicle").toObject();
    UserInfo tmpInfo;
    tmpInfo.account=subObj["user_type"].toInt();
    tmpInfo.password=subObj["user_password"].toString().toStdString();

    UserCommandData commandIn;
    //目标点位置
    commandIn.targetPosition = subObj["target_position"].toInt();   //1重启　0关机
    commandIn.comment = subObj["comment"].toString().toStdString(); //注释
    commandIn.userIp = subObj["user_ip"].toString().toStdString();  //用户IP

    int returnFlag = 0;
    powerManage->addCommand(commandIn,returnFlag);

    QJsonObject obj_root;
    QJsonObject obj_result;

    obj_result.insert("result", QString::number(returnFlag));
    obj_root.insert("response_set_call_vehicle", obj_result);
    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();
    sendMsgText(pClientIn,tmpString);

    return 1;
}
QString WebSocketServer::longTimeToTimeString(long timeIn)
{
    time_t timep;
    struct tm* p;
    timep = timeIn;
    p=localtime(&timep);//从tm结构体中可以取到年月日时分秒等值。
    char szTmp[50] = {0};
    strftime(szTmp,50,"%Y-%m-%d %H:%M:%S",p);    //这里输出的将是 p的时间值

    return  QString(QLatin1String(szTmp));
}

